﻿@model SAIM.Models.TicketData
@using SAIM.Models
@{
    SAIMIdentity UserIdentity = new SAIMIdentity(User.Identity);
    ViewBag.Title = "Usuarios colaboradores";
}

@section css {
    @Styles.Render("~/Content/typeahead")
}

<div class="page-header">
    <h2>@ViewBag.Title</h2>
</div>
<div class="panel panel-default table-responsive">
    <ul class="list-group col-md-6" style="padding-left:15px;">
        <li class="list-group-item list-group-item-text"><b>Información del ticket</b> [ <a href="@Url.Action("Summary", "Tickets", new { id = Model.IdTicket })">Regresar</a> ]</li>
        <li class="list-group-item" style="border-bottom: none;">
            <dl class="dl-horizontal">
                <dt>Número de ticket:</dt>
                <dd>@Model.IdTicket</dd>
            </dl>
            <dl class="dl-horizontal">
                <dt>Área:</dt>
                <dd>@Model.Area</dd>
            </dl>
            <dl class="dl-horizontal">
                <dt>Servicio:</dt>
                <dd>@Model.Issue</dd>
            </dl>
            <dl class="dl-horizontal">
                <dt>Fecha y hora:</dt>
                <dd>@Model.TicketDate</dd>
            </dl>
        </li>
    </ul>
    <ul class="list-group col-md-6" style="padding-left:15px;">
        <li class="list-group-item list-group-item-text" style="border-top: none;"><b>Información del usuario</b></li>
        <li class="list-group-item">
            <dl class="dl-horizontal">
                <dt>Usuario:</dt>
                <dd>@Model.UserName</dd>
            </dl>
            <dl class="dl-horizontal">
                <dt>UPN:</dt>
                <dd>@Model.RPE</dd>
            </dl>
            <dl class="dl-horizontal">
                <dt>Correo electrónico:</dt>
                <dd>@Model.Email</dd>
            </dl>
            <dl class="dl-horizontal">
                <dt>Perfil:</dt>
                <dd>@Model.Profile</dd>
            </dl>
        </li>
    </ul>
</div>
<p class="text-success">@ViewBag.StatusMessage</p>
@Html.ValidationSummary("", new { @class = "text-danger" })
<div class="panel panel-default">
    <div class="panel-heading">
        @if ( ((UserIdentity.GetUserId() == Model.RPE) || ViewBag.IsAdmin) && !Model.Closed)
        {
            using (Html.BeginForm("Users", "Tickets", FormMethod.Post, new { @class = "form-horizontal", role = "form", id = "users-form" }))
            {
                @Html.AntiForgeryToken()
                @Html.Hidden("TicketId", Model.IdTicket);
                <div class="form-group" style="margin-bottom:0px;">
                    <div class="col-sm-2 text-primary"><h5><b>Colaboradores:</b></h5></div>
                    <div class="col-sm-1">
                        <input class="input-validation-error" style="visibility:hidden;" data-val="true" data-val-required="Ningún usuario seleccionado" id="UPN" name="UPN" value="" type="text">
                    </div>
                    <div class="col-sm-6 col-sm-offset-3">
                        <div class="input-group">
                            <input type="text" class="form-control typeahead" placeholder="Buscar usuario..." autocomplete="off" />
                            <span class="input-group-btn">
                                <button id="btn-submit" class="btn btn-primary" type="submit">Agregar</button>
                            </span>
                        </div>
                        <span class="text-danger field-validation-error" data-valmsg-for="UPN" data-valmsg-replace="true"></span>
                    </div>
                </div>
            }
        }
        else
        {
            <div class="text-primary"><h5><b>Colaboradores:</b></h5></div>
        }
    </div>
    @using (Html.BeginForm("RemoveUser", "Tickets", FormMethod.Post, new { role = "form", id = "grid-users-form" }))
    {
        @Html.AntiForgeryToken()
        @Html.Hidden("UPN", "", new { id = "row-UPN" });
        @Html.Hidden("TicketId", Model.IdTicket);
        <div class="table-responsive">
            <table id="grid-users" class="table table-striped">
                <thead>
                    <tr class="info">
                        @if ( ((UserIdentity.GetUserId() == Model.RPE) || ViewBag.IsAdmin) && !Model.Closed)
                        {
                            <th data-column-id="Options" data-formatter="link">Opciones</th>
                        }
                        <th data-column-id="UPN">UPN</th>
                        <th data-column-id="Name">Nombre</th>
                    </tr>
                </thead>
            </table>
        </div>
    }
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/bundles/typeahead")
    <script type="text/javascript">
        urlUsers = '@Url.Action("GetTypeaheadUsers", "Users")/?id=%QUERY';
        urlGridUsers = '@Url.Action("GetTicketUsers", "Tickets", new { Id = Model.IdTicket })';
        function getColumn(column, row) {
            var components = '<div title="Eliminar usuario">' +
                    '<button type="button" class="remove-user btn btn-primary" data-id="' + row.UPN + '">' +
                        '<span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button></div>';
            return components;
        }</script>
    <script type="text/javascript" src="@Url.Content("~/Scripts/Tickets/Users.js")"></script>
}